<template>
    <div class="productList">
      <el-row type="flex" class="row-bg" justify="space-around" style="flex-wrap:wrap">
        <el-col :span="5" v-for="(product, index) in products" :key="product.id" style="margin-bottom: 20px;">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="'/products/' + product.imgPath" class="image">
          <div style="padding: 14px;">
            <span class="productName">{{product.productName}}</span>
            <p class="des">{{product.description}}</p>
            <div class="bottom clearfix">
               <time class="time"></time>
              <el-button type="text" class="button" @click="goDetail(product.id)">查看详情</el-button>
        </div>
      </div>
    </el-card>
  </el-col>
</el-row>
        </div>
        
  </template>
  
  <script>
  export default {
    name: 'ProductListView',
    data(){
        return {
           products:{}
        }
    },
    methods:{
      goDetail(pId) {
         this.$router.push('/detail?productId=' + pId)
    }
  },
  created(){
        this.axios.get('/api/getAllProducts')
        .then(res=>{
          console.log('res:',res.data.data)
          this.products = res.data.data
        })
    }
  }
  </script>
  <style lang="scss" scoped>
   .productName{
    text-align: center;
    font-size: 18px;
    font-weight: 700;
  }
  .des{
    color: #949494;
    font-size: 14px;
  }
    .time {
    font-size: 13px;
    color: #999;
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
    position: relative;
    right: 5px;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }
  </style>